package com.wash.shoes.controller.pc;


import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.R;
import com.wash.shoes.entity.CustomerPo;
import com.wash.shoes.service.CustomerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ljg
 * @since 2024-08-28
 */
@Api(tags = {"PC-客户"})
@RestController
@RequestMapping({"/customer", "/dev-api/customer"})
public class CustomerController {

    @Autowired
    CustomerService customerService;

    @ApiOperation("获取客户列表")
    @PostMapping("/list")
    public R<Page<CustomerPo>> pageList(@RequestBody CustomerPo customerPo) {
        Page<CustomerPo> page = customerService.pageList(customerPo);
        return R.ok(page);
    }

    @ApiOperation("修改新增客户信息,有id为修改没有为新增")
    @PostMapping("/saveUpdate")
    public R<CustomerPo> add(@RequestBody CustomerPo customerPo) {
        if (ObjectUtil.isEmpty(customerPo.getId())) {
            customerPo.setStatus(1);
            customerService.save(customerPo);
        } else {
            customerService.updateById(customerPo);
        }
        return R.ok(customerPo);
    }

    @ApiOperation("获取详情")
    @PostMapping("/getDetailById")
    public R<CustomerPo> getDetailById(String theId) {
        CustomerPo customerPo = customerService.getById(theId);
        return R.ok(customerPo);
    }


    @ApiOperation("获取详情用电话")
    @PostMapping("/getDetailByPhone")
    public R<CustomerPo> getDetailByPhone(String getDetailByPhone) {
        CustomerPo customerPo = customerService.getByPhone(getDetailByPhone);
        return R.ok(customerPo);
    }

}

